package com.roadjava.demo01;

import com.roadjava.demo01.bean.UserInfo1;

public class ValidationTest1 {
    public static void main(String[] args) {
        UserInfo1 userInfo = new UserInfo1();
        userInfo.setName("");

        test1(userInfo);
    }

    // 传统的方式校验 bean
    private static void test1(UserInfo1 userInfo) {
        String name = userInfo.getName();
        if (name == null || "".equals(name) || "".equals(name.trim())) {
            throw new RuntimeException("name不符合校验规则");
        }

        Integer age = userInfo.getAge();
        if (age == null || age < 1 || age > 800) {
            throw new RuntimeException("age不符合校验规则");
        }
    }
}